package com.cadre.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cadre.common.exception.CadreException;
import com.cadre.common.utils.common.DateUtils;
import com.cadre.common.utils.oldutil.*;
import com.cadre.system.domain.officer.A04;
import com.cadre.system.domain.officer.B01;
import com.cadre.system.domain.officer.DIC_ZB;
import com.cadre.system.domain.officer.PersonVO;
import com.cadre.system.mapper.A19Mapper;
import com.cadre.system.mapper.B01Mapper;
import com.cadre.system.mapper.ReportMapper;
import com.cadre.system.service.A04Service;
import com.cadre.system.service.DIC_ZBService;
import com.cadre.system.service.ReportService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

@Service
public class ReportServiceImpl implements ReportService {
    @Autowired
    private ReportMapper reportMapper;
    @Autowired
    private A19Mapper a19Mapper;
    @Autowired
    private A04Service a04Service;
    @Resource
    private DIC_ZBService dIC_ZBService;
    @Autowired
    private B01Mapper b01Mapper;
    @Autowired
    private ReportConfig config;

    @Override
    public ResultVO selectPersonListById(String ids) {
        if (StringUtils.isEmpty(ids)) {
            throw new CadreException(ResultEnum.NULL_ERROR);
        }
        List<PersonVO> list = this.reportMapper.selectPersonListById(Arrays.asList(StringUtils.split(ids, ",")));
        if (CollectionUtils.isEmpty(list)) {
            return ResultVOUtil.success(list);
        }
        for (PersonVO vo : list) {
            getName(vo);
            getAa01(vo);
            getAa02(vo);
            getA0191(vo);
            getA0187(vo);
        }
        return ResultVOUtil.success(list);
    }

    @Override // com.tdqy.cadre.modular.profess.service.ReportService
    public ResultVO selectPersonListByIdNoUnit(String ids) {
//        if (StringUtils.isEmpty(ids)) {
//            throw new CadreException(ResultEnum.NULL_ERROR);
//        }
        List<PersonVO> list = this.reportMapper.selectPersonListByIdNoUnit(Arrays.asList(StringUtils.split(ids, ",")));
        if (CollectionUtils.isEmpty(list)) {
            return ResultVOUtil.success(list);
        }
        for (PersonVO vo : list) {
            getName(vo);
            getAa01(vo);
            getAa02(vo);
            getA0191(vo);
            getA0187(vo);
        }
        return ResultVOUtil.success(list);
    }

    @Override // com.tdqy.cadre.modular.profess.service.ReportService
    public ResultVO listGroupByUnit(String ids) {
        if (StringUtils.isEmpty(ids)) {
            throw new CadreException(ResultEnum.NULL_ERROR);
        }
        List<String> idList = Arrays.asList(StringUtils.split(ids, ","));
        List<PersonVO> list = this.reportMapper.selectPersonListById(idList);
        for (PersonVO vo : list) {
            getName(vo);
            getAa01(vo);
            getAa02(vo);
            getA0191(vo);
        }
        List<B01> b01s = this.b01Mapper.selectBatchIds(idList);
        Map<String, Object> map = new HashMap<>();
        List<PersonVO> reslutList = new ArrayList<>();
        for (B01 b01 : b01s) {
            String b0101 = b01.getB0101();
            if (StringUtils.isNotBlank(b0101)) {
                reslutList.addAll ((List) list.stream().filter(p -> {
                    return b0101.equals(p.getB0101());
                }).collect(Collectors.toList()));
            }
        }
        map.put("data" , reslutList);
        return ResultVOUtil.success(map);
    }

    @Override // com.tdqy.cadre.modular.profess.service.ReportService
    public PageUtils selectPersonListForName(Map<String, Object> map) {
        String att1;
        map.put("page", (String) map.get("pageNum"));
        map.put("limit", (String) map.get("pageSize"));
        String att12 = map.get("name") == null ? "" : map.get("name").toString().trim();
        if (!(att12 == null || att12 == "" || (att1 = att12.replaceAll("，", ",").toUpperCase()) == null || att1.length() == 0)) {
            map.put("names", att1.split(","));
        }
        Page<PersonVO> page = new Query(map).getPage();
        List<PersonVO> list = this.reportMapper.selectPersonListForName(page, map);
        for (PersonVO vo : list) {
            getName(vo);
            getAa01(vo);
            getAa02(vo);
            getA0191(vo);
        }
        return new PageUtils(page.setRecords(list));
    }

    @Override // com.tdqy.cadre.modular.profess.service.ReportService
    public List<PersonVO> getListByIdList(List list1) {
        List<PersonVO> list = new ArrayList<>();
        if (CollectionUtils.isEmpty(list1)) {
            return list;
        }
        for (int i = 0; i < list1.size(); i++) {
            PersonVO vo = this.reportMapper.getListById(list1.get(i).toString());
            getName(vo);
            getAa01(vo);
            getAa02(vo);
            getA0191(vo);
            getA0187(vo);
            list.add(vo);
        }
        return list;
    }

    @Override // com.tdqy.cadre.modular.profess.service.ReportService
    public List<PersonVO> getListByIdListXj(List list1) {
        List<PersonVO> list = new ArrayList<>();
        if (CollectionUtils.isEmpty(list1)) {
            return list;
        }
        for (int i = 0; i < list1.size(); i++) {
            PersonVO vo = this.reportMapper.getListById(list1.get(i).toString());
            getName(vo);
            getAa01(vo);
            getAa02Xianji(vo);
            getAa02Fc(vo);
            getAa02Zc(vo);
            getA0191(vo);
            getA0187(vo);
            if (vo.getA0179() != null && (vo.getA0179().contains("省") || vo.getA0179().contains("厅") || vo.getA0179().contains("处") || vo.getA0179().contains("县"))) {
                list.add(vo);
            }
        }
        return list;
    }

    @Override // com.tdqy.cadre.modular.profess.service.ReportService
    public List<PersonVO> getListByIdListXj1(List list1) {
        List<PersonVO> list = new ArrayList<>();
        if (CollectionUtils.isEmpty(list1)) {
            return list;
        }
        for (int i = 0; i < list1.size(); i++) {
            PersonVO vo = this.reportMapper.getListById(list1.get(i).toString());
            getName(vo);
            getAa01(vo);
            getAa02Xianji(vo);
            getAa02Fc(vo);
            getAa02Zc(vo);
            getA0191(vo);
            getA0187(vo);
            list.add(vo);
        }
        return list;
    }

    @Override // com.tdqy.cadre.modular.profess.service.ReportService
    public List<PersonVO> getListByIdListKj(List list1) {
        List<PersonVO> list = new ArrayList<>();
        if (CollectionUtils.isEmpty(list1)) {
            return list;
        }
        for (int i = 0; i < list1.size(); i++) {
            PersonVO vo = this.reportMapper.getListById(list1.get(i).toString());
            getName(vo);
            getAa01(vo);
            getAa02Xianji(vo);
            getAa02Fk(vo);
            getAa02Zk(vo);
            getA0191(vo);
            getA0187(vo);
            if (vo.getA0179() == null || (!vo.getA0179().contains("省") && !vo.getA0179().contains("厅") && !vo.getA0179().contains("处") && !vo.getA0179().contains("县"))) {
                list.add(vo);
            }
        }
        return list;
    }

    @Override // com.tdqy.cadre.modular.profess.service.ReportService
    public List<PersonVO> getListByIdListKj1(List list1) {
        List<PersonVO> list = new ArrayList<>();
        if (CollectionUtils.isEmpty(list1)) {
            return list;
        }
        for (int i = 0; i < list1.size(); i++) {
            PersonVO vo = this.reportMapper.getListById(list1.get(i).toString());
            getName(vo);
            getAa01(vo);
            getAa02Xianji(vo);
            getAa02Fk(vo);
            getAa02Zk(vo);
            getA0191(vo);
            getA0187(vo);
            list.add(vo);
        }
        return list;
    }

    private void getA0187(PersonVO vo) {
        DIC_ZB dicGb6864;
        DIC_ZB dicXueli;
        A04 a04;
        if (null != vo) {
            List<A04> a04s = this.a04Service.selectList(vo.getFlowid());
            if (org.apache.commons.collections.CollectionUtils.isNotEmpty(a04s)) {
                List<A04> qrz = (List) a04s.stream().filter(a042 -> {
                    return a042.getA0449().equals("1");
                }).collect(Collectors.toList());
                List<A04> zz = (List) a04s.stream().filter(a042 -> {
                    return a042.getA0449().equals("2");
                }).collect(Collectors.toList());
                if (org.apache.commons.collections.CollectionUtils.isNotEmpty(qrz) && null != (a04 = qrz.stream().min(new Comparator<A04>() { // from class: com.tdqy.cadre.modular.profess.service.impl.ReportServiceImpl.1
                    public int compare(A04 o1, A04 o2) {
                        String a1 = o1.getA0460();
                        String a2 = o2.getA0460();
                        if (StringUtils.isNotBlank(a1) && a1.length() < 2) {
                            a1 = a1 + 0;
                        }
                        if (StringUtils.isNotBlank(a2) && a2.length() < 2) {
                            a2 = a2 + 0;
                        }
                        if ((StringUtils.isNotBlank(a1) ? Integer.parseInt(a1) : 0) > (StringUtils.isNotBlank(a2) ? Integer.parseInt(a2) : 0)) {
                            return 1;
                        }
                        return -1;
                    }
                }).get())) {
                    DIC_ZB dicXueli2 = this.dIC_ZBService.selectByTableNameAndCode("DIC_XUELI", a04.getA0460());
                    StringBuffer sb = new StringBuffer();
                    if (null != dicXueli2) {
                        sb.append(dicXueli2.getName());
                    }
                    sb.append("\n");
                    DIC_ZB dicGb68642 = this.dIC_ZBService.selectByTableNameAndCode("DIC_GB6864", a04.getA0463());
                    if (null != dicGb68642) {
                        sb.append(dicGb68642.getName());
                    }
                    vo.setA0187(sb.toString());
                }
                if (org.apache.commons.collections.CollectionUtils.isNotEmpty(zz)) {
                    A04 a04XueLi = zz.stream().min(new Comparator<A04>() { // from class: com.tdqy.cadre.modular.profess.service.impl.ReportServiceImpl.2
                        public int compare(A04 o1, A04 o2) {
                            String a1 = o1.getA0460();
                            String a2 = o2.getA0460();
                            if (StringUtils.isNotBlank(a1) && a1.length() < 2) {
                                a1 = a1 + 0;
                            }
                            if (StringUtils.isNotBlank(a2) && a2.length() < 2) {
                                a2 = a2 + 0;
                            }
                            if ((StringUtils.isNotBlank(a1) ? Integer.parseInt(a1) : 0) > (StringUtils.isNotBlank(a2) ? Integer.parseInt(a2) : 0)) {
                                return 1;
                            }
                            return -1;
                        }
                    }).get();
                    A04 a04XueWei = zz.stream().min(new Comparator<A04>() { // from class: com.tdqy.cadre.modular.profess.service.impl.ReportServiceImpl.3
                        public int compare(A04 o1, A04 o2) {
                            String a1 = o1.getA0463();
                            String a2 = o2.getA0463();
                            if (StringUtils.isBlank(a1)) {
                                return -1;
                            }
                            if (StringUtils.isBlank(a2)) {
                                return 1;
                            }
                            if (a1.length() < 3) {
                                a1 = a1 + 0;
                            }
                            if (a2.length() < 3) {
                                a2 = a2 + 0;
                            }
                            if (Integer.parseInt(a1) > Integer.parseInt(a2)) {
                                return 1;
                            }
                            return -1;
                        }
                    }).get();
                    StringBuffer sb2 = new StringBuffer();
                    if (!(null == a04XueLi || null == (dicXueli = this.dIC_ZBService.selectByTableNameAndCode("DIC_XUELI", a04XueLi.getA0460())))) {
                        sb2.append(dicXueli.getName());
                    }
                    sb2.append("\n");
                    if (!(null == a04XueWei || null == (dicGb6864 = this.dIC_ZBService.selectByTableNameAndCode("DIC_GB6864", a04XueWei.getA0463())))) {
                        sb2.append(dicGb6864.getName());
                    }
                    vo.setA0190(sb2.toString());
                }
            }
        }
    }

    private void getA0191(PersonVO vo) {
        if (vo.getA0191() != null) {
            String a0191 = vo.getA0191();
            if (a0191.contains(" ")) {
                a0191 = a0191.substring(0, a0191.indexOf(" "));
                vo.setA0191(a0191);
            }
            if (a0191.contains("\n")) {
                a0191 = a0191.substring(0, a0191.indexOf("\n"));
                vo.setA0191(a0191);
            }
            if (a0191.contains("\r")) {
                vo.setA0191(a0191.substring(0, a0191.indexOf("\r")));
            }
        }
    }

    private void getRemark(PersonVO vo) {
        StringBuffer strB = new StringBuffer();
        //（已调整完毕） todo:进行sql转换
        LambdaQueryWrapper<A04> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(A04::getPersonid, vo.getFlowid());
        lambdaQueryWrapper.eq(A04::getA0449, "1");
        lambdaQueryWrapper.orderByAsc(A04::getA0415);
        List<A04> list = this.a04Service.getBaseMapper().selectList(lambdaQueryWrapper);
        if (list.size() > 1) {
            boolean flag = false;
            for (int i = 1; i < list.size(); i++) {
                String str = "";
                if (flag) {
                    strB.append("；");
                    flag = false;
                }
                if (list.get(i).getA0405() != null && list.get(i).getA0405().trim().length() > 0) {
                    str = str + list.get(i).getA0405() + "：";
                    flag = true;
                }
                if (list.get(i).getA0435() != null && list.get(i).getA0435().trim().length() > 0) {
                    str = str + list.get(i).getA0435();
                    flag = true;
                }
                if (list.get(i).getA0411() != null && list.get(i).getA0411().trim().length() > 0) {
                    str = str + list.get(i).getA0411();
                    flag = true;
                }
                strB.append(str);
            }
        }
        vo.setRemark(strB.toString());
    }

    private void getName(PersonVO vo) {
        String a0105 = vo.getA0105();
        boolean b = StringUtils.isNotEmpty(a0105) && "女".equals(a0105);
        String a0130 = vo.getA0130();
        boolean b1 = StringUtils.isNotEmpty(a0130) && !"汉族".equals(a0130);
        StringBuilder sb = new StringBuilder();
        if (b && !b1) {
            sb.append("(女)");
        }
        if (b && b1) {
            sb.append("(女,");
            sb.append(a0130);
            sb.append(")");
        }
        if (!b && b1) {
            sb.append("(");
            sb.append(a0130);
            sb.append(")");
        }
        if (StringUtils.isNotBlank(sb.toString())) {
            vo.setA0101(vo.getA0101() + "\n" + sb.toString());
        }
    }

    private void getAa01(PersonVO vo) {
        Date a0106 = vo.getA0106();
        if (a0106 != null) {
            int age = AgeUtil.getCurrentAge(a0106);
            String time = new SimpleDateFormat(DateUtil.MONTG_DATE_FORMAT).format(a0106);
            vo.setAa01(time + "\n(" + age + ")");
        }
    }

    private void getAa02(PersonVO vo) {
        Map<String, String> map = new HashMap<>();
        map.put("省部级正职", "正省");
        map.put("省部级副职", "副省");
        map.put("厅局级正职", "正厅");
        map.put("厅局级副职", "副厅");
        map.put("县处级正职", "正处");
        map.put("县处级副职", "副处");
        map.put("比照正厅级", "正厅");
        map.put("比照副厅级", "副厅");
        map.put("比照正处级", "正处");
        map.put("一级巡视员", "一巡");
        map.put("二级巡视员", "二巡");
        map.put("一级调研员", "一调");
        map.put("二级调研员", "二调");
        map.put("三级调研员", "三调");
        map.put("四级调研员", "四调");
        map.put("乡科级正职", "正科");
        map.put("乡科级副职", "副科");
        map.put("科员", "科员");
        map.put("办事员", "办事员");
        map.put("一级主任科员", "一级主任科员");
        map.put("二级主任科员", "二级主任科员");
        map.put("三级主任科员", "三级主任科员");
        map.put("四级主任科员", "四级主任科员");
        StringBuilder sb = new StringBuilder();
        if (vo.getA0180() != null) {
            sb.append(DateUtils.format(vo.getA0180(), DateUtil.MONTG_DATE_FORMAT));
        }
        if (!(vo.getA0179() == null || vo.getA0179().equals("") || map.get(vo.getA0179()) == null)) {
            if (sb.length() > 0) {
                sb.append("\n");
            }
            sb.append(map.get(vo.getA0179()));
        }
        if (vo.getA0142() != null) {
            if (sb.length() > 0) {
                sb.append("\n");
            }
            sb.append(DateUtils.format(vo.getA0142(), DateUtil.MONTG_DATE_FORMAT));
        }
        if (!(vo.getA0198() == null || vo.getA0198().equals("") || map.get(vo.getA0198()) == null)) {
            if (sb.length() > 0) {
                sb.append("\n");
            }
            sb.append(map.get(vo.getA0198()));
        }
        vo.setAa02(sb.toString());
    }

    private void getAa02Xianji(PersonVO vo) {
        Map<String, Object> mapZj = new HashMap<>();
        mapZj.put("tableName", "DIC_ZB1009");
        List<DIC_ZB> listZj = this.dIC_ZBService.getAll(mapZj);
        Map<String, String> map = new HashMap<>();
        for (int i = 0; i < listZj.size(); i++) {
            if ("一级巡视员".equals(listZj.get(i).getName())) {
                map.put("一级巡视员", "一巡");
            } else if ("二级巡视员".equals(listZj.get(i).getName())) {
                map.put("二级巡视员", "二巡");
            } else if ("一级调研员".equals(listZj.get(i).getName())) {
                map.put("一级调研员", "一调");
            } else if ("二级调研员".equals(listZj.get(i).getName())) {
                map.put("二级调研员", "二调");
            } else if ("三级调研员".equals(listZj.get(i).getName())) {
                map.put("三级调研员", "三调");
            } else if ("四级调研员".equals(listZj.get(i).getName())) {
                map.put("四级调研员", "四调");
            } else if ("一级主任科员".equals(listZj.get(i).getName())) {
                map.put("一级主任科员", "一级主任科员");
            } else if ("二级主任科员".equals(listZj.get(i).getName())) {
                map.put("二级主任科员", "二级主任科员");
            } else if ("三级主任科员".equals(listZj.get(i).getName())) {
                map.put("三级主任科员", "三级主任科员");
            } else if ("四级主任科员".equals(listZj.get(i).getName())) {
                map.put("四级主任科员", "四级主任科员");
            } else {
                map.put(listZj.get(i).getName(), listZj.get(i).getName());
            }
        }
        StringBuilder sb = new StringBuilder();
        if (vo.getA0142() != null) {
            if (sb.length() > 0) {
                sb.append("\n");
            }
            sb.append(DateUtils.format(vo.getA0142(), DateUtil.MONTG_DATE_FORMAT));
        }
        if (!(vo.getA0198() == null || vo.getA0198().equals("") || map.get(vo.getA0198()) == null)) {
            if (sb.length() > 0) {
                sb.append("\n");
            }
            sb.append(map.get(vo.getA0198()));
        }
        vo.setAa02(sb.toString());
    }

    private void getAa02Fc(PersonVO vo) {
        new HashMap<>().put("县处级副职", "副处");
        StringBuilder sb = new StringBuilder();
        Date fkDate = null;
        try {
            if (vo.getA0180() == null || !vo.getA0179().equals("县处级副职")) {
                Map<String, Object> map1 = new HashMap<>();
                map1.put("personid", vo.getFlowid());
                map1.put("a1930", "县处级副职");
                Date minDate = this.a19Mapper.selectMinDateByPerson(map1);
                if (minDate != null) {
                    fkDate = minDate;
                }
            } else {
                fkDate = vo.getA0180();
                Map<String, Object> map12 = new HashMap<>();
                map12.put("personid", vo.getFlowid());
                map12.put("a1930", "县处级副职");
                map12.put("a0180", DateUtils.format(vo.getA0180(), DateUtil.MONTG_DATE_FORMAT));
                Date minDate2 = this.a19Mapper.selectMinDateByPerson(map12);
                if (minDate2 != null) {
                    fkDate = minDate2;
                }
            }
            if (fkDate != null) {
                sb.append(DateUtils.format(fkDate, DateUtil.MONTG_DATE_FORMAT));
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        vo.setAa03(sb.toString());
    }

    private void getAa02Fk(PersonVO vo) {
        new HashMap<>().put("乡科级副职", "副科");
        StringBuilder sb = new StringBuilder();
        Date fkDate = null;
        try {
            if (vo.getA0180() == null || !vo.getA0179().equals("乡科级副职")) {
                Map<String, Object> map1 = new HashMap<>();
                map1.put("personid", vo.getFlowid());
                map1.put("a1930", "乡科级副职");
                Date minDate = this.a19Mapper.selectMinDateByPerson(map1);
                if (minDate != null) {
                    fkDate = minDate;
                }
            } else {
                fkDate = vo.getA0180();
                Map<String, Object> map12 = new HashMap<>();
                map12.put("personid", vo.getFlowid());
                map12.put("a1930", "乡科级副职");
                map12.put("a0180", DateUtils.format(vo.getA0180(), DateUtil.MONTG_DATE_FORMAT));
                Date minDate2 = this.a19Mapper.selectMinDateByPerson(map12);
                if (minDate2 != null) {
                    fkDate = minDate2;
                }
            }
            if (fkDate != null) {
                sb.append(DateUtils.format(fkDate, DateUtil.MONTG_DATE_FORMAT));
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        vo.setAa03(sb.toString());
    }

    private void getAa02Zc(PersonVO vo) {
        Map<String, String> map = new HashMap<>();
        map.put("县处级正职", "正处");
        map.put("比照正处级", "正处");
        StringBuilder sb = new StringBuilder();
        Date fkDate = null;
        try {
            if (vo.getA0180() == null || !vo.getA0179().equals("县处级正职")) {
                Map<String, Object> map1 = new HashMap<>();
                map1.put("personid", vo.getFlowid());
                map1.put("a1930", "县处级正职");
                Date minDate = this.a19Mapper.selectMinDateByPerson(map1);
                if (minDate != null) {
                    fkDate = minDate;
                }
            } else {
                fkDate = vo.getA0180();
                Map<String, Object> map12 = new HashMap<>();
                map12.put("personid", vo.getFlowid());
                map12.put("a1930", "县处级正职");
                map12.put("a0180", DateUtils.format(vo.getA0180(), DateUtil.MONTG_DATE_FORMAT));
                Date minDate2 = this.a19Mapper.selectMinDateByPerson(map12);
                if (minDate2 != null) {
                    fkDate = minDate2;
                }
            }
            if (fkDate != null) {
                sb.append(DateUtils.format(fkDate, DateUtil.MONTG_DATE_FORMAT));
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        vo.setAa04(sb.toString());
    }

    private void getAa02Zk(PersonVO vo) {
        new HashMap<>().put("乡科级正职", "正科");
        StringBuilder sb = new StringBuilder();
        Date fkDate = null;
        try {
            if (vo.getA0180() == null || !vo.getA0179().equals("乡科级正职")) {
                Map<String, Object> map1 = new HashMap<>();
                map1.put("personid", vo.getFlowid());
                map1.put("a1930", "乡科级正职");
                Date minDate = this.a19Mapper.selectMinDateByPerson(map1);
                if (minDate != null) {
                    fkDate = minDate;
                }
            } else {
                fkDate = vo.getA0180();
                Map<String, Object> map12 = new HashMap<>();
                map12.put("personid", vo.getFlowid());
                map12.put("a1930", "乡科级正职");
                map12.put("a0180", DateUtils.format(vo.getA0180(), DateUtil.MONTG_DATE_FORMAT));
                Date minDate2 = this.a19Mapper.selectMinDateByPerson(map12);
                if (minDate2 != null) {
                    fkDate = minDate2;
                }
            }
            if (fkDate != null) {
                sb.append(DateUtils.format(fkDate, DateUtil.MONTG_DATE_FORMAT));
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        vo.setAa04(sb.toString());
    }

    @Override // com.tdqy.cadre.modular.profess.service.ReportService
    public ResultVO selectPersonListByMap(Map<String, Object> map) {
        String ids = "";
        try {
            ids = String.valueOf(map.get("ids"));
        } catch (Exception e) {
        }
        if (StringUtils.isEmpty(ids)) {
            throw new CadreException(ResultEnum.NULL_ERROR);
        }
        map.put("ids", Arrays.asList(StringUtils.split(ids, ",")));
        Map<String, Object> mapZj = new HashMap<>();
        mapZj.put("tableName", "DIC_ZB1009");
        List<DIC_ZB> listZj = this.dIC_ZBService.getAll(mapZj);
        String fromRankNew = (String) map.get("A0198Start");
        String toRankNew = (String) map.get("A0198End");
        if (!(!(fromRankNew == null || fromRankNew.isEmpty()) || toRankNew == null || toRankNew.length() == 0)) {
            try {
                fromRankNew = listZj.get(listZj.size() - 1).getName();
            } catch (Exception e2) {
            }
        }
        if (!(fromRankNew == null || fromRankNew.length() == 0 || !(toRankNew == null || toRankNew.isEmpty()))) {
            try {
                toRankNew = listZj.get(0).getName();
            } catch (Exception e3) {
            }
        }
        String rankNew = "";
        boolean startFlag = false;
        boolean stopFlag = false;
        if (!(fromRankNew == null || fromRankNew.length() == 0 || toRankNew == null || toRankNew.length() == 0)) {
            for (int i = 0; i < listZj.size(); i++) {
                if (listZj.get(i).getName().equals(fromRankNew)) {
                    startFlag = true;
                }
                if (startFlag && !stopFlag) {
                    rankNew = rankNew + listZj.get(i).getName() + ",";
                }
                if (listZj.get(i).getName().equals(toRankNew)) {
                    stopFlag = true;
                }
            }
            if (rankNew.equals("")) {
                rankNew = "";
                boolean startFlag2 = false;
                boolean stopFlag2 = false;
                for (int i2 = listZj.size() - 1; i2 >= 0; i2--) {
                    if (listZj.get(i2).getName().equals(fromRankNew)) {
                        startFlag2 = true;
                    }
                    if (startFlag2 && !stopFlag2) {
                        rankNew = rankNew + listZj.get(i2).getName() + ",";
                    }
                    if (listZj.get(i2).getName().equals(toRankNew)) {
                        stopFlag2 = true;
                    }
                }
            }
            map.put("rank", rankNew.split(","));
        }
        Map<String, Object> mapZc = new HashMap<>();
        mapZc.put("tableName", "DIC_ZB09");
        List<DIC_ZB> listZc = this.dIC_ZBService.getAll(mapZc);
        String fromRank = (String) map.get("A0179Start");
        String toRank = (String) map.get("A0179End");
        if (!(!(fromRank == null || fromRank.isEmpty()) || toRank == null || toRank.length() == 0)) {
            try {
                fromRank = listZc.get(listZc.size() - 1).getName();
            } catch (Exception e4) {
            }
        }
        if (!(fromRank == null || fromRank.length() == 0 || !(toRank == null || toRank.isEmpty()))) {
            try {
                toRank = listZc.get(0).getName();
            } catch (Exception e5) {
            }
        }
        String rankTNew = "";
        boolean startFlag1 = false;
        boolean stopFlag1 = false;
        if (!(fromRank == null || fromRank.length() == 0 || toRank == null || toRank.length() == 0)) {
            for (int i3 = 0; i3 < listZc.size(); i3++) {
                if (listZc.get(i3).getName().equals(fromRank)) {
                    startFlag1 = true;
                }
                if (startFlag1 && !stopFlag1) {
                    rankTNew = rankTNew + listZc.get(i3).getName() + ",";
                }
                if (listZc.get(i3).getName().equals(toRank)) {
                    stopFlag1 = true;
                }
            }
            if (rankTNew.equals("")) {
                rankTNew = "";
                boolean startFlag12 = false;
                boolean stopFlag12 = false;
                for (int i4 = listZc.size() - 1; i4 >= 0; i4--) {
                    if (listZc.get(i4).getName().equals(fromRank)) {
                        startFlag12 = true;
                    }
                    if (startFlag12 && !stopFlag12) {
                        rankTNew = rankTNew + listZc.get(i4).getName() + ",";
                    }
                    if (listZc.get(i4).getName().equals(toRank)) {
                        stopFlag12 = true;
                    }
                }
            }
            map.put("rankNew", rankTNew.split(","));
        }
        String fromTime1 = (String) map.get("A0180Start");
        String toTime1 = (String) map.get("A0180End");
        if (fromTime1 == null || fromTime1.length() == 0 || toTime1 == null || toTime1.length() != 0) {
        }
        String fromTime2 = (String) map.get("A0142Start");
        String toTime2 = (String) map.get("A0142End");
        if (fromTime2 == null || fromTime2.length() == 0 || toTime2 == null || toTime2.length() != 0) {
        }
        Map<String, Object> map5 = new HashMap<>();
        map5.put("tableName", "DIC_XUELI");
        List<DIC_ZB> listXueli = this.dIC_ZBService.getAll(map5);
        String fromXueli = (String) map.get("A0405Start");
        String toXueli = (String) map.get("A0405End");
        if (!(!(fromXueli == null || fromXueli.isEmpty()) || toXueli == null || toXueli.length() == 0)) {
            try {
                fromXueli = listXueli.get(listXueli.size() - 1).getCode();
            } catch (Exception e6) {
            }
        }
        if (!(fromXueli == null || fromXueli.length() == 0 || !(toXueli == null || toXueli.isEmpty()))) {
            try {
                toXueli = listXueli.get(0).getCode();
            } catch (Exception e7) {
            }
        }
        String xueLiNew = "";
        boolean startFlag22 = false;
        boolean stopFlag22 = false;
        if (!(fromXueli == null || fromXueli.length() == 0 || toXueli == null || toXueli.length() == 0)) {
            for (int i5 = 0; i5 < listXueli.size(); i5++) {
                if (listXueli.get(i5).getCode().equals(fromXueli)) {
                    startFlag22 = true;
                }
                if (startFlag22 && !stopFlag22) {
                    xueLiNew = xueLiNew + listXueli.get(i5).getCode() + ",";
                }
                if (listXueli.get(i5).getCode().equals(toXueli)) {
                    stopFlag22 = true;
                }
            }
            if (xueLiNew.equals("")) {
                xueLiNew = "";
                boolean startFlag23 = false;
                boolean stopFlag23 = false;
                for (int i6 = listXueli.size() - 1; i6 >= 0; i6--) {
                    if (listXueli.get(i6).getCode().equals(fromXueli)) {
                        startFlag23 = true;
                    }
                    if (startFlag23 && !stopFlag23) {
                        xueLiNew = xueLiNew + listXueli.get(i6).getCode() + ",";
                    }
                    if (listXueli.get(i6).getCode().equals(toXueli)) {
                        stopFlag23 = true;
                    }
                }
            }
            map.put("xueli", xueLiNew.split(","));
        }
        String quanrizhi = (String) map.get("A0449");
        String isQuickQuery = (String) map.get("quickQuery");
        if (isQuickQuery == null || "Y".equals(isQuickQuery)) {
        }
        map.put("A0449", quanrizhi);
        try {
            String ageStart1 = (String) map.get("ageStart1");
            String ageEnd1 = (String) map.get("ageEnd1");
            if (ageStart1 != null && !ageStart1.isEmpty() && ageEnd1 != null && !ageEnd1.isEmpty() && ageStart1.equals(ageEnd1)) {
                map.put("ageStart", ageStart1);
                map.put("ageEnd", String.valueOf(Integer.parseInt(ageEnd1) + 1));
                map.remove("ageStart1");
                map.remove("ageEnd1");
            }
        } catch (Exception e8) {
        }
        try {
            String a0180Start = (String) map.get("A0180Start");
            String a0180End = (String) map.get("A0180End");
            if (a0180Start != null && !a0180Start.isEmpty() && a0180End != null && !a0180End.isEmpty() && a0180Start.equals(a0180End)) {
                map.put("A0180Start1", a0180Start);
                map.put("A0180End1", String.valueOf(Integer.parseInt(a0180End) + 1));
                map.remove("A0180Start");
                map.remove("A0180End");
            }
        } catch (Exception e9) {
        }
        try {
            String a0185Start = (String) map.get("A0142Start");
            String a0185End = (String) map.get("A0142End");
            if (a0185Start != null && !a0185Start.isEmpty() && a0185End != null && !a0185End.isEmpty() && a0185Start.equals(a0185End)) {
                map.put("A0142Start1", a0185Start);
                map.put("A0142End1", String.valueOf(Integer.parseInt(a0185End) + 1));
                map.remove("A0142Start");
                map.remove("A0142End");
            }
        } catch (Exception e10) {
        }
        try {
            String a0185Start2 = (String) map.get("A0185Start");
            String a0185End2 = (String) map.get("A0185End");
            if (a0185Start2 != null && !a0185Start2.isEmpty() && a0185End2 != null && !a0185End2.isEmpty() && a0185Start2.equals(a0185End2)) {
                map.put("A0185Start1", a0185Start2);
                map.put("A0185End1", String.valueOf(Integer.parseInt(a0185End2) + 1));
                map.remove("A0185Start");
                map.remove("A0185End");
            }
        } catch (Exception e11) {
        }
        List<PersonVO> list = this.reportMapper.selectPersonListByMap(map);
        if (CollectionUtils.isEmpty(list)) {
            return ResultVOUtil.success(list);
        }
        for (PersonVO vo : list) {
            getName(vo);
            getAa01(vo);
            getAa02(vo);
            getA0191(vo);
        }
        return ResultVOUtil.success(list);
    }

    @Override // com.tdqy.cadre.modular.profess.service.ReportService
    public List<PersonVO> getListByIdList2(List flowidList) {
        List<PersonVO> list = new ArrayList<>();
        if (CollectionUtils.isEmpty(flowidList)) {
            return list;
        }
        for (int i = 0; i < flowidList.size(); i++) {
            PersonVO vo = this.reportMapper.getListById2(flowidList.get(i).toString());
            getName(vo);
            getAa01(vo);
            getAa02(vo);
            getA0191(vo);
            getA0187(vo);
            list.add(vo);
        }
        return list;
    }

    @Override // com.tdqy.cadre.modular.profess.service.ReportService
    public List<PersonVO> getListByIdListHBT(List flowidList) {
        List<PersonVO> list = new ArrayList<>();
        if (CollectionUtils.isEmpty(flowidList)) {
            return list;
        }
        for (int i = 0; i < flowidList.size(); i++) {
            PersonVO vo = this.reportMapper.getListByIdHBT(flowidList.get(i).toString());
            getAa01(vo);
            getAa02(vo);
            getA0191(vo);
            getA0187(vo);
            list.add(vo);
        }
        return list;
    }

    @Override // com.tdqy.cadre.modular.profess.service.ReportService
    public List<Map<String, Object>> getListByIdListCustom(List flowidList, String[] fields, List<String> tables) {
        return this.reportMapper.getListByIdListCustom(flowidList, fields, tables);
    }
}
